<script setup lang="ts">
import {computed, inject, ref, watch} from "vue";
import {Message} from "@arco-design/web-vue";
import bonusPercentageBill from '@/api/finance/bonusPercentageBill'
import WriteOffButton from '@/views/finance/components/writeOffButton.vue'
const size = ref('small');
const crudRef = inject('crudRef')
const record = inject('record')
const getDictData = inject('getDictData')
const refreshRecode = inject('refreshRecode')
const edit = ()=>crudRef.value.crudFormRef.edit(record.value)
const InfoDataLeft = ref([])
const InfoDataRight = ref([])
const audit = ref(1)
const writeOffButton = ref()
watch(record, (value) => {
  if(value.id == undefined){
    return;
  }
  audit.value = record.value.status
  console.log('刷新基础信息--'+record.value.id)
   InfoDataLeft.value =  [
      {label: '账单号：', value: record.value.id},
      {label: '用户：', value: getDictData('user_id',record.value.user_id)},
      {label: '账单日期：', value: record.value.bill_date},
      {label: '到期时间：', value: record.value.expire_date},
      // {label: '到期动作：', value: getDictData('expire_action',record.value.expire_action)},
    ]
   InfoDataRight.value = [
      {label: '状态：', value: getDictData('status',record.value.status)},
      {label: '币种：', value: getDictData('currency',record.value.currency)},
      {label: '账单金额：', value: record.value.amount},
      {label: '流水金额：', value: record.value.statement_amount},
      {label: '已支付：', value: record.value.audit_amount},
      {label: '未支付：', value: record.value.unaudit_amount},
      {label: '备注：', value: record.value.memo},
      {label: '审核备注：', value: record.value.check_memo},
    ]
})

const auditFuc = async (type) => {
  let res
    if(type){
       res = await bonusPercentageBill.auditPass({ids:[record.value.id]})
    }else{
      res = await bonusPercentageBill.auditRefuse({ids:[record.value.id]})
    }
    if(!res.success)
    {
      Message.error(res.message)
      return;
    }
    Message.success(res.message)
    refreshRecode(true)
}
</script>
<template>
  <a-grid-item :span="24">
    <a-collapse :default-active-key="['1']" class="g-collapse">
      <a-collapse-item header="基础信息" key="1">
        <template #extra>
          <a-button-group>
            <a-button type="primary" size="small" @click.stop="edit" v-auth="['finance:bonusPercentageBill:update']"><icon-edit/>编辑</a-button>
            <a-button type="primary" size="small" @click.stop=""><icon-download/>下载</a-button>
            <a-popconfirm
            content="确定审核吗?"
            position="bottom"
            @ok="auditFuc(true)"
            v-if="audit == 1"
            >
            <a-button v-if="record.status != 3" type="primary" size="small" @click.stop="" v-auth="['finance:bonusPercentageBill:audit']"><icon-check/>审核</a-button>
            </a-popconfirm>
            <a-popconfirm
            content="确定取消审核吗?"
            position="bottom"
            @ok="auditFuc(false)"
            v-else
            >
            <a-button v-if="record.status != 3" type="primary" size="small"  @click.stop="" v-auth="['finance:bonusPercentageBill:audit']"><icon-check/>取消审核</a-button>
            </a-popconfirm>
            <write-off-button :deduction="false" :call="refreshRecode" :auth="['finance:bonusPercentageBill:writeOffPass']" :api="bonusPercentageBill.writeOffPass" ref="writeOffButton" />
          </a-button-group>
        </template>
        <a-row class="">
          <a-col :span="12">
            <a-descriptions  :data="InfoDataLeft" :size="size" :column="1"  />
          </a-col>
          <a-col :span="12">
            <a-descriptions  :data="InfoDataRight" :size="size" :column="1"  />
          </a-col>
        </a-row>
      </a-collapse-item>
    </a-collapse>
  </a-grid-item>
</template>

<style scoped>

</style>